package demo03;
//外观数列
class Solution {
    public String countAndSay(int n) {
        String ret = "1";
        while(n>1){
            StringBuilder tmp = new StringBuilder();
            int len = ret.length();
            for(int left =0,right = 0; right < len;){
                while(right<len &&(ret.charAt(left) == ret.charAt(right))){
                    right++;
                }
                tmp.append(Integer.toString(right -left));
                tmp.append(ret.charAt(left));
                left = right;
            }
            n--;
            ret = tmp.toString();
        }
        return ret;
    }
}
